<?php

use Phinx\Db\Adapter\MysqlAdapter;
use think\migration\Migrator;
use think\migration\db\Column;

class CreateTableFriend extends Migrator
{
    public function up()
    {
        if (!$this->hasTable('friend')) {
            $table = $this->table('friend', ['engine' => 'MyISAM'])
                ->setId('id')
                ->setPrimaryKey('id')
                ->setComment('微信好友列表');
            $table->addColumn('nickname', 'string', ['limit' => 100, 'null' => false, 'comment' => '微信昵称'])
                ->addColumn('note', 'string', ['limit' => 100, 'null' => false, 'comment' => '备注'])
                ->addColumn('robot_wxid', 'string', ['limit' => 100, 'null' => false, 'default' => '', 'comment' => '机器人id'])
                ->addColumn('wx_num', 'string', ['limit' => 100, 'null' => false, 'default' => '', 'comment' => '微信账号'])
                ->addColumn('wxid', 'string', ['limit' => 100, 'null' => false, 'default' => '', 'comment' => '微信通讯ID'])
                ->addColumn('headimgurl', 'string', ['limit' => 200, 'null' => false, 'default' => '', 'comment' => '微信头像'])
                ->addColumn('sex', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => '0', 'comment' => '性别 0-无 1-男 2-女'])
                ->addColumn('add_time', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '创建时间'])
                ->create();
        }
    }

    public function down()
    {
        if ($this->hasTable('friend')) {
            $this->dropTable('friend');
        }
    }
}
